package com.wei.czz.framework.blog.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wei.czz.framework.blog.dao.BlogStatsFlowDao;
import com.wei.czz.framework.blog.entity.BlogStatsFlowEntity;
import com.wei.czz.framework.blog.service.BlogStatsFlowService;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-03-01 22:34:26
 * className: BlogStatsFlowServiceImpl
 * version: 1.0
 * description:
 */
@Service("blogStatsFlowService")
public class BlogStatsFlowServiceImpl extends ServiceImpl<BlogStatsFlowDao, BlogStatsFlowEntity>
        implements BlogStatsFlowService {

    private static final Logger log = LoggerFactory.getLogger(BlogStatsFlowServiceImpl.class);

    @Transactional
    @Override
    public void batchSaveBlogStatsFlow(List<BlogStatsFlowEntity> blogStatsFlowList) {
        boolean bool = this.saveBatch(blogStatsFlowList);
        log.info("批量保存博客统计流水完成。bool={}", bool);
        if (!bool) {
            log.error("批量保存博客统计流水失败。{}", blogStatsFlowList);
        }
    }

    @Override
    public List<BlogStatsFlowEntity> getUserBlogStats(Long userId, Integer type, Integer valueType, Date startDate,
                                                      Date endDate) {
        List<BlogStatsFlowEntity> blogStatsFlowList = baseMapper.getUserBlogStats(userId, type, valueType, startDate,
                endDate);
        if (blogStatsFlowList.isEmpty()) {
            log.info("用户已发布博客统计流水查询结果为空。userId={}, type={}, valueType={}, startDate={}, endDate={}",
                    userId, type, valueType, startDate, endDate);
        }
        return blogStatsFlowList;
    }
}